package cn.micai.base.zookeeper;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

/**
 * @Auther: zhaoxinguo
 * @Date: 2018/8/24 10:41
 * @Description: 当zookeeper节点状态发生变化时，通过watcher机制，可以让客户端得到通知
 */
public class ZookeeperWatcher implements Watcher {

    @Override
    public void process(WatchedEvent event) {
        // 删除节点
        if (event.getType() == Event.EventType.NodeDeleted) {
            System.out.println("node delete");
        }
        // 修改节点的子节点
        if (event.getType() == Event.EventType.NodeChildrenChanged) {
            System.out.println("node NodeChildrenChanged");
        }
        // 创建节点
        if (event.getType() == Event.EventType.NodeCreated) {
            System.out.println("node NodeCreated");
        }
        // 修改节点数据
        if (event.getType() == Event.EventType.NodeDataChanged) {
            System.out.println("node NodeDataChanged");
        }
    }
}
